package com.springsecutity.secutity.controller;

import com.springsecutity.secutity.entity.Msg;
import com.springsecutity.secutity.entity.error;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class HomeController {
    @RequestMapping("/")
    public String index(Model model) {
        Msg msg = new Msg("测试标题", "测试内容", "额外信息，只对管理员展示,注销请求");
        model.addAttribute("msg", msg);
        return "index";
    }

    @RequestMapping("/login/error")
    public String error(Model model) {
        error error = new error("登录失败，请您重新登录", "");
        model.addAttribute("param", error);
        return "login";
    }

    @PreAuthorize("hasRole('ROLE_USER')" )
    @RequestMapping("/getName")
    @ResponseBody
    public String getName() {
        System.out.println(".....");
        return "asd";
    }
}
